<HTML> 
<HEAD> 
	<TITLE>3rd Party ROBOTC Drivers</TITLE> 
<link href="tabs.css" rel="stylesheet" type="text/css"/> 
<link href="doxygen.css" rel="stylesheet" type="text/css"/> 
</HEAD> 
 
<BODY bgcolor="#ffffff" link="#000000" vlink="#000000"> 
<table width="100%" bgcolor="navy" cellspacing=0 cellpadding=1 border=0> 
<tr><td><table width="100%" bgcolor="#EEEEDD" cellspacing=0 cellpadding=3 border=0> 
<tr> 
    <td width="33%" align="left"> <img src="images/LOGO_NXT.gif" width=266 height=44 border="0" alt="Mindstorms"></td> 
    <td><b><font size="+3" color="navy">3rd Party ROBOTC Drivers</font></b></td> 
    <td align="right"> <img src="images/logo.png" width=44 height=44 border="0" alt="RobotC"></td>     
</tr> 
  <tr bgcolor="#cccc99" align="right"> 
          <td colspan=3> <font face="arial" size="-1"> [<a href=main.html>Home</a>] [<a target=_top href="https://sourceforge.net/projects/rdpartyrobotcdr/">Download</a>] [<a target=_top href="http://apps.sourceforge.net/mantisbt/rdpartyrobotcdr/my_view_page.php">Submit a bug/suggestion</a>]  [<a target=_top href="http://www.robotc.net/forums/">ROBOTC Forums</a>] [<a target=_top href="http://botbench.com">Blog</a>] [<a target=_top href="http://sourceforge.net/donate/index.php?group_id=257238">Support this project</a>]</font> </td> 
</tr> 
</table></td></tr> 
</table> 
<!-- Generated by Doxygen 1.7.2 -->
<div class="header">
  <div class="headertitle">
<h1>mindsensors-pfmate-test1.c</h1>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><span class="preprocessor">#pragma config(Sensor, S1,     MSPFM,               sensorI2CCustom)</span>
<span class="preprocessor"></span><span class="comment">//*!!Code automatically generated by &#39;ROBOTC&#39; configuration wizard               !!*//</span>

<span class="comment">/*</span>
<span class="comment"> * $Id: mindsensors-pfmate-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
<span class="comment"></span>
<span class="comment">/**</span>
<span class="comment"> * mindsensors-pfmate.h provides an API for the Mindsensors PFMate.  This program</span>
<span class="comment"> * demonstrates how to use that API.</span>
<span class="comment"> *</span>
<span class="comment"> * Changelog:</span>
<span class="comment"> * - 0.1: Initial release</span>
<span class="comment"> * - 0.2: More comments</span>
<span class="comment"> *</span>
<span class="comment"> * Credits:</span>
<span class="comment"> * - Big thanks to Mindsensors for providing me with the hardware necessary to write and test this.</span>
<span class="comment"> *</span>
<span class="comment"> * License: You may use this code as you wish, provided you give credit where it&#39;s due.</span>
<span class="comment"> *</span>
<span class="comment"> * THIS CODE WILL ONLY WORK WITH ROBOTC VERSION 3.59 AND HIGHER. </span>
<span class="comment"></span>
<span class="comment"> * Xander Soldaat (xander_at_botbench.com)</span>
<span class="comment"> * 28 November 2009</span>
<span class="comment"> * version 0.2</span>
<span class="comment"> */</span>

<span class="preprocessor">#include &quot;<a class="code" href="mindsensors-pfmate_8h.html" title="Mindsensors PFMate Sensor driver.">drivers/mindsensors-pfmate.h</a>&quot;</span>

<span class="keywordtype">void</span> doTest(<span class="keywordtype">int</span> channel) {
  nxtDisplayTextLine(5, <span class="stringliteral">&quot;Chan:  %d&quot;</span>, channel);

  <span class="comment">// -------- testing motor A -----------------------</span>
  PlaySound(soundBeepBeep);
  <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();
  nxtDisplayTextLine(6, <span class="stringliteral">&quot;Motor: A&quot;</span>);
  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   fwd&quot;</span>);
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> speed = 1; speed &lt; 8; speed++) {
    <span class="comment">// Run motor A forward from speed 1 to 7</span>
    <a name="a0"></a><a class="code" href="group__pfmate.html#ga1542c504ac26bc3da9410fab1d1ed996">MSPFMcontrolMotorA</a>(MSPFM, channel, <a name="a1"></a><a class="code" href="group__pfmate.html#ga548757e965bce1f636e74f5493cb2871">MSPFM_FORWARD</a>, speed);
    wait1Msec(500);
  }

  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   brake&quot;</span>);
  <span class="comment">// Brake the motor</span>
  <a class="code" href="group__pfmate.html#ga1542c504ac26bc3da9410fab1d1ed996">MSPFMcontrolMotorA</a>(MSPFM, channel, <a name="a2"></a><a class="code" href="group__pfmate.html#ga24b05cd721ebedd747d39212b10f13cb">MSPFM_BRAKE</a>, 0);
  wait1Msec(500);

  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   rev&quot;</span>);
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> speed = 1; speed &lt; 8; speed++) {
    <span class="comment">// Run motor A in reverse from speed 1 to 7</span>
    <a class="code" href="group__pfmate.html#ga1542c504ac26bc3da9410fab1d1ed996">MSPFMcontrolMotorA</a>(MSPFM, channel, <a name="a3"></a><a class="code" href="group__pfmate.html#gac9680e5a49cf90582263eab3ffd47fff">MSPFM_REVERSE</a>, speed);
    wait1Msec(500);
  }

  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   float&quot;</span>);
  <span class="comment">// Set motor A to float</span>
  <a class="code" href="group__pfmate.html#ga1542c504ac26bc3da9410fab1d1ed996">MSPFMcontrolMotorA</a>(MSPFM, channel, <a name="a4"></a><a class="code" href="group__pfmate.html#ga367064634cae523bf2838d6839baf0fa">MSPFM_FLOAT</a>, 0);
  wait1Msec(500);

  <span class="comment">// -------- testing motor B -----------------------</span>
  PlaySound(soundBeepBeep);
  <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();
  nxtDisplayTextLine(6, <span class="stringliteral">&quot;Motor: B&quot;</span>);
  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   fwd&quot;</span>);
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> speed = 1; speed &lt; 8; speed++) {
    <span class="comment">// Run motor B forward from speed 1 to 7</span>
    <a name="a5"></a><a class="code" href="group__pfmate.html#ga7d5254dbfb7257fbb4afce2a4eec904f">MSPFMcontrolMotorB</a>(MSPFM, channel, <a class="code" href="group__pfmate.html#ga548757e965bce1f636e74f5493cb2871">MSPFM_FORWARD</a>, speed);
    wait1Msec(500);
  }

  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   brake&quot;</span>);
  <a class="code" href="group__pfmate.html#ga7d5254dbfb7257fbb4afce2a4eec904f">MSPFMcontrolMotorB</a>(MSPFM, channel, <a class="code" href="group__pfmate.html#ga24b05cd721ebedd747d39212b10f13cb">MSPFM_BRAKE</a>, 0);
  wait1Msec(500);

  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   rev&quot;</span>);
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> speed = 1; speed &lt; 8; speed++) {
    <span class="comment">// Run motor B in reverse from speed 1 to 7</span>
    <a class="code" href="group__pfmate.html#ga7d5254dbfb7257fbb4afce2a4eec904f">MSPFMcontrolMotorB</a>(MSPFM, channel, <a class="code" href="group__pfmate.html#gac9680e5a49cf90582263eab3ffd47fff">MSPFM_REVERSE</a>, speed);
    wait1Msec(500);
  }

  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   float&quot;</span>);
  <a class="code" href="group__pfmate.html#ga7d5254dbfb7257fbb4afce2a4eec904f">MSPFMcontrolMotorB</a>(MSPFM, channel, <a class="code" href="group__pfmate.html#ga367064634cae523bf2838d6839baf0fa">MSPFM_FLOAT</a>, 0);
  wait1Msec(500);

  <span class="comment">// -------- testing motor A+B -----------------------</span>
  PlaySound(soundBeepBeep);
  <span class="keywordflow">while</span>(bSoundActive) EndTimeSlice();
  nxtDisplayTextLine(6, <span class="stringliteral">&quot;Motor: A+B&quot;</span>);
  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   fwd+rev&quot;</span>);
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> speed = 1; speed &lt; 8; speed++) {
    <span class="comment">// Run motor A forward and motor B in reverse from speed 1 to 7</span>
    <a name="a6"></a><a class="code" href="group__pfmate.html#ga58009d0e4e8387d37024407c156b0da9">MSPFMcontrolMotorAB</a>(MSPFM, channel, <a class="code" href="group__pfmate.html#ga548757e965bce1f636e74f5493cb2871">MSPFM_FORWARD</a>, speed, <a class="code" href="group__pfmate.html#gac9680e5a49cf90582263eab3ffd47fff">MSPFM_REVERSE</a>, speed);
    wait1Msec(500);
  }

  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   brake&quot;</span>);
  <span class="comment">// brake both motors A and B</span>
  <a class="code" href="group__pfmate.html#ga58009d0e4e8387d37024407c156b0da9">MSPFMcontrolMotorAB</a>(MSPFM, channel, <a class="code" href="group__pfmate.html#ga24b05cd721ebedd747d39212b10f13cb">MSPFM_BRAKE</a>, 0, <a class="code" href="group__pfmate.html#ga24b05cd721ebedd747d39212b10f13cb">MSPFM_BRAKE</a>, 0);
  wait1Msec(500);

  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   rev+fwd&quot;</span>);
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> speed = 1; speed &lt; 8; speed++) {
    <span class="comment">// Run motor A in revese and motor B forward from speed 1 to 7</span>
    <a class="code" href="group__pfmate.html#ga58009d0e4e8387d37024407c156b0da9">MSPFMcontrolMotorAB</a>(MSPFM, channel, <a class="code" href="group__pfmate.html#gac9680e5a49cf90582263eab3ffd47fff">MSPFM_REVERSE</a>, speed, <a class="code" href="group__pfmate.html#ga548757e965bce1f636e74f5493cb2871">MSPFM_FORWARD</a>, speed);
    wait1Msec(500);
  }

  nxtDisplayTextLine(7, <span class="stringliteral">&quot;Dir:   float&quot;</span>);
  <span class="comment">// Put both motors in float</span>
  <a class="code" href="group__pfmate.html#ga58009d0e4e8387d37024407c156b0da9">MSPFMcontrolMotorAB</a>(MSPFM, channel, <a class="code" href="group__pfmate.html#ga367064634cae523bf2838d6839baf0fa">MSPFM_FLOAT</a>, 0, <a class="code" href="group__pfmate.html#ga367064634cae523bf2838d6839baf0fa">MSPFM_FLOAT</a>, 0);
  wait1Msec(500);
}

task main() {
  nxtDisplayCenteredTextLine(0, <span class="stringliteral">&quot;Mindsensors&quot;</span>);
  nxtDisplayCenteredBigTextLine(1, <span class="stringliteral">&quot;PFMate&quot;</span>);
  nxtDisplayCenteredTextLine(3, <span class="stringliteral">&quot;Test 1&quot;</span>);
  wait1Msec(2000);

  <span class="comment">// Run through each channel for testing.</span>
  <span class="keywordflow">for</span> (<span class="keywordtype">int</span> channel = 1; channel &lt; 5; channel++) {
    doTest(channel);
  }
}

<span class="comment">/*</span>
<span class="comment"> * $Id: mindsensors-pfmate-test1.c 133 2013-03-10 15:15:38Z xander $</span>
<span class="comment"> */</span>
</pre></div> </div>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Wed Mar 13 2013 19:56:42 for ROBOTC Drivers by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.2 </small></address>
</body>
</html>
